package com.wpre.blogsystem.controller;

import com.wpre.blogsystem.common.pojo.request.UserLoginParam;
import com.wpre.blogsystem.common.pojo.response.UserInfoResponse;
import com.wpre.blogsystem.common.pojo.response.UserLoginResponse;
import com.wpre.blogsystem.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-12-04
 * Time: 13:45
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource(name = "userServiceImpl")
    private UserService userService;

    @PostMapping("/login")
    public UserLoginResponse login(@Validated @RequestBody UserLoginParam user) {
        //@Validated校验实体类参数,在对应类中的属性进行校验
        log.info("用户登录:username{}", user.getUserName());
        return userService.login(user);
    }

    //实现注册功能
    @PostMapping("/register")
    public boolean register(@Validated @RequestBody UserLoginParam user) {
        //@Validated校验实体类参数,在对应类中的属性进行校验
        log.info("用户注册:username{}", user.getUserName());
        return userService.register(user);
    }

    //获取当前用户信息
    @GetMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull Integer userId) {
        log.info("获取用户信息{}", userId);
        return userService.getUserInfoById(userId);
    }


    @GetMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull Integer blogId) {
        log.info("获取作者信息{}", blogId);
        return userService.getAuthorInfo(blogId);
    }


}
